package com.wenwei.paper.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wenwei.paper.R;
import com.wenwei.paper.bean.ReplenishmentListBean;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/13.
 */
public class ReplenishmentNotifyAdapter extends RecyclerView.Adapter<ReplenishmentNotifyAdapter.MyViewHolder> {

    private CallBack mCallBack;

    public interface CallBack {
        void onItemClick(int id);
    }

    private ArrayList<ReplenishmentListBean> mList;

    public void setReplenishmentData(ArrayList<ReplenishmentListBean> list) {
        this.mList = list;
    }

    public ReplenishmentNotifyAdapter(CallBack callBack) {
        mCallBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_replenishment, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCallBack != null) {
                    mCallBack.onItemClick(mList.get(position).getChargelistId());
                }
            }
        });
        holder.replenishmentAddress.setText("地址："+mList.get(position).getAddress());
        holder.replenishmentNumber.setText("柜号："+mList.get(position).getNum());
        holder.replenishmentTime.setText(mList.get(position).getTime());
        if(mList.get(position).getStatus() == 0){
            holder.dianImg.setVisibility(View.VISIBLE);
        }else {
            holder.dianImg.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.dian_img)
        ImageView dianImg;
        @Bind(R.id.replenishment_state)
        TextView replenishmentState;
        @Bind(R.id.replenishment_number)
        TextView replenishmentNumber;
        @Bind(R.id.replenishment_address)
        TextView replenishmentAddress;
        @Bind(R.id.replenishment_time)
        TextView replenishmentTime;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
